package ArrayPackage;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author Lzm
 * @version 1.0
 */
public class minSubArrayLen_ {
  public int minSubArrayLen(int target, int[] nums) {
    if (nums.length == 0){
      return 0;
    }
    int sum = 0;
    int left = 0;
    int result = Integer.MAX_VALUE;
    int subLength = 0;
    for (int right = 0 ; right < nums.length ; right++){
      sum += nums[right];
      while(sum >= target){
        subLength = right - left + 1;
        result = Math.min(result,subLength);
        sum -= nums[left++];
      }
    }
    return result == Integer.MAX_VALUE ? 0 : result;
  }
}
